pub mod control_flow {
    use rand::Rng; // 引入随机数包

    pub fn test_while(){
        // while
        let mut i:u16 = 1;
        while i<10 {
            if i == 2  {
                i+=1;
                continue;
            }
            println!("while:{}",i.to_string());
            i+=1;
        }
    }

    pub fn test_loop(){
        // while
        let mut i:u16 = 1;
        loop {
            println!("loop:{}",i.to_string());
            i+=1;
            if i>10 {
                break;
            }
        }
    }

    pub fn test_match(){
        let mut rng = rand::thread_rng();
        let num = rng.gen_range(0..10);

        match num {
            2=>println!("num:{}==2",&num), // 等于2的时候
            5..=9=>println!("num:{}大于等于5，小于等于9",&num), // 大于5小于等于9的时候
            _=>println!("num:{},其他的情况",&num)
        }
    }

    // 基本函数
    pub fn base_function()->i32 {
        5 // 最后不加分号自动return
        // return 5;
    }

    // 闭包
    pub fn closure_function()->i32 {
        let sum = |a:i32,b:i32|->i32{a+b};
        return sum(1,2);
    }
}